// Copyright Abhijeet Nayak @2013
// Please contact abhijeet@cise.ufl.edu before copying the code

#ifndef DBFILE_H
#define DBFILE_H

#include "TwoWayList.h"
#include "Record.h"
#include "Schema.h"
#include "File.h"
#include "Comparison.h"
#include "ComparisonEngine.h"

typedef enum {heap, sorted, tree} fType;


class DBFile {
private: 
	
	//File datastructure to hold pages
	File file;
	//Page datastructure to hold the group of records
	Page page;
	//Record datastructure to hold the single instance of schema data
	Record record;
	//Total no of pages in the file
	off_t NoOfPages;
	//Keep the page count in GetNext
	off_t CurrentPage;
	//Path of the binary file database
	char *f_path;
	//Comaprison engine to compare two records
	ComparisonEngine comp;
	
public:
	DBFile (); 
	//Create a new binary database to save file instances
	int Create (char *fpath, fType file_type, void *startup);
	
	//Open the binary databse to read the file instances from it
	int Open (char *fpath);
	
	//Close the binary
	int Close ();
	
	//Copy from loadpath and save it binary DB file 
	//create by Create() method. 
	void Load (Schema &myschema, char *loadpath);

	//Move to first record in the file
	void MoveFirst ();
	
	//Add a new record to the file
	void Add (Record &addme);
	
	//Get next record from the file
	int GetNext (Record &fetchme);
	
	//Get next record from the file where it satisfies the cnf rule
	int GetNext (Record &fetchme, CNF &cnf, Record &literal);

};
#endif
